package com.wanye.service;

import com.wanye.entity.Content;
import com.wanye.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wanye on 2017/9/28.
 */
@Service
public class LoginService {

    @Autowired
    private UserService userService;
    @Autowired
    private ContentService contentService;

    public Map<String, Object> login(int id) {

        contentService.check();// 验证

        User user = userService.getUserById(id);// 通过id读取用户信息

        // 通过用户名读取文章列表
        List<Content> contents = contentService.getContentByUserName(user.getName());

        // 组装用户信息和文章列表
        Map<String,Object> res = new HashMap();

        res.put("user", user);
        res.put("contents", contents);

        return res;

    }

}
